iT邦幫忙

2023 iThome 鐵人賽

DAY 21
0
SideProject30

行事曆不再NG:Notion API&Google Calendar跨平台整合發想系列 第 21

Day 21 Notion API & Google Calendar API Integration

  • 分享至 

  • xImage
  •  

今天先來講一下API整合的部分

Architecture

下面有簡單畫的架構圖

https://ithelp.ithome.com.tw/upload/images/20231006/20140869CNt3x9390H.png

以前使用heroku好像不用錢,但現在要綁信用卡了QQ

既然都要綁卡,倒不如用AWS的服務,順便學一下AWS Cloud

因此目前的想法是這樣,會先把Backend API架在EC2上面,這隻程式的核心邏輯就會在這邊

然後用Lambda當作Schedule Job,可能每10分鐘戳一次Backend API

最後就是DB的部分,原本有想說可以用DynamoDB來當資料庫,但是擔心用太多服務會變成需要收錢

想到最省錢的方法應該就是用notion的DB當成是db,反正可以從這邊用API撈資料

並且呈現也是直接用這個db呈現,所以就先這樣試試看

因此Backend API會需要寫資料到Notion db,而Notion db也會將資料庫的資料回傳給Backend API

Spec

規格的部分還是今天先想一下好了,反正今天都要用架構圖了

openapi: 3.0.0
info:
  title: Notion and Google Calendar Integration API
  version: 1.0.0
  description: API for integrating Notion and Google Calendar

paths:
  /notion/createNotionDatabase/{pageId}:
    post:
      summary: Create a Notion database
      parameters:
        - name: pageId
          in: path
          required: true
          description: ID of the Notion page to create the database under
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: array
                  items:
                    type: string
                properties:
                  type: object
                  description: JSON object defining database properties
      responses:
        '201':
          description: Notion database created successfully
        '400':
          description: Invalid input

  /notion/queryNotionDatabase/{databaseId}:
    post:
      summary: Query data from a Notion database
      parameters:
        - name: databaseId
          in: path
          required: true
          description: ID of the Notion database to query
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                filter:
                  type: object
                  description: JSON object defining query filters
                sorts:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Query results from Notion database
        '400':
          description: Invalid input

  /notion/updateNotionDatabase/{databaseId}:
    patch:
      summary: Update a Notion database
      parameters:
        - name: databaseId
          in: path
          required: true
          description: ID of the Notion database to update
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: array
                  items:
                    type: string
                description:
                  type: array
                  items:
                    type: string
                properties:
                  type: object
                  description: JSON object defining updated database properties
      responses:
        '200':
          description: Notion database updated successfully
        '400':
          description: Invalid input

  /googleCalendar/getGoogleCalendarEventList/{calendarId}:
    get:
      summary: Get a list of events from Google Calendar
      parameters:
        - name: calendarId
          in: path
          required: true
          description: ID of the Google Calendar to retrieve events from
          schema:
            type: string
      responses:
        '200':
          description: List of events from Google Calendar
        '404':
          description: Calendar not found

這邊會有4隻API

前面三隻是用來對Notion API進行操作的,主要是Create DB,查詢資料跟寫入資料

最後一隻是從Google Calendar那邊拿Event List的API

目前Notion DB的設計很簡單

Notion DB Example
Title Doctor
DateTime October 6, 2023 7:00 PM → 8:00 PM

就大概像這樣而已,原本想說要把顏色加進來,但好像要用API insert資料到google calendar才能夠用color id

到這邊DB,API spec跟架構圖大概都出來了

再來就是照圖施工了🚧


上一篇
Day 20 Google Calendar API in Go vol.2
下一篇
Day 22 Notion API & Google Calendar API Integration - Create Notion Database
系列文
行事曆不再NG:Notion API&Google Calendar跨平台整合發想30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言